<?php
namespace jy_yiliao;
defined('BY_JYA') or exit('error');
/*
	本插件：$this->model('model')->方法名();
	其他地方调用：model('jy_cmso2o/model')->方法名();
*/
class model extends \plugin{
	public function get($params,&$total=null,$lat_lng=array()){
		if(!$params['orderby']){
			$params['orderby']=array('id desc');
		}
		$list=$this->pdo_getlist('store',$params,$total);
		foreach($list as &$v){
			$v['lat_lng']=json_decode($v['lat_lng'],true);
			$v['juli']=cfc('tools')->getdistance($lat_lng['lng'],$lat_lng['lat'],$v['lat_lng']['lng'],$v['lat_lng']['lat']);
			$v['juli']=intval($v['juli']/1000);
		}
		paixu($return['list'],'juli','asc');
		return $list;
	}
	public function checkdangan($mid='',$params=array()){
		$mid=$mid?:$_SESSION['uid'];
		$this->checkuser($mid,$params);
		$body=pdo_get('jy_yiliao_body',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$mid));
		if(!$body['id']){
			exi('请先完善个人档案！','error','jy_yiliao/set/');
		}
		return true;
	}
	public function checkuser($mid='',$params=array()){
		$mid=$mid?:$_SESSION['uid'];
		$user=pdo_get('jy_yiliao_user',array('mid'=>$mid,'uniacid'=>$_SESSION['uniacid']));
		if(empty($user) && $mid){
			if($params['workerid']){
				$params['fromuser']=$params['fromuser']?:pdo_getcolumn('jy_kabao_worker',array('uniacid'=>$_SESSION['uniacid'],'id'=>$params['workerid']),'mid');
			}
			if($params['fromuser']){
				$_SESSION['fromuser']=$params['fromuser'];
				pdo_update('core_members',array('fromuser'=>$params['fromuser']),array('fromuser'=>0,'id'=>$mid,'uniacid'=>$_SESSION['uniacid']));
			}
			$data=array(
				'mid'=>$mid,
				'createtime'=>time(),
				'uniacid'=>$_SESSION['uniacid'],
				'from_type'=>$params['from_type'],
				'fromuser'=>$params['fromuser']?:$_SESSION['fromuser'],
				'fromworkerid'=>$params['workerid'],
				'storeid'=>$params['storeid'],
			);
			pdo_insert('jy_yiliao_user',$data);
		}
		return true;
	}
	public function msgtpl_tags($area){
		$tags=array(
			array('title'=>'通用类','data'=>array(
				array('name'=>'平台名称'),
				array('name'=>'粉丝昵称'),
			)),
			array('title'=>'订单类','data'=>array(
				array('name' => '平台名称'),
				array('name' => '粉丝昵称'),
				array('name' => '订单号'),
				array('name' => '订单金额'),
				array('name' => '科室名称'),
				array('name' => '科室老师'),
				array('name' => '班级名称'),
				array('name' => '班主任'),
				array('name' => '监护人'),
				array('name' => '监护人电话'),
				array('name' => '学员姓名'),
				array('name' => '下单时间'),
				array('name' => '支付时间'),
				array('name' => '取消时间'),
				array('name' => '门店'),
				array('name' => '门店地址'),
				array('name' => '门店联系人'),
				array('name' => '门店营业时间'),
				array('name' => '学号'),
				array('name' => '备注信息'),
				array('name' => '当前时间'),
		))
		);
		return $tags;
	}
}